<HEAD>
  <SCRIPT SRC="../ganja.js"></SCRIPT>
</HEAD>
<BODY><SCRIPT>
// Create a Clifford Algebra with 3,1 metric for 2D CGA. 
Algebra(3,1,()=>{ 

// The conformal model adds in more element types. (circles, point-pairs)
// We no longer work in a dual space. (so ^ = join and & = meet)
// Vectors are points, Bivectors are point pairs, Trivectors are lines/circles

// We don't work directly in the e3/e4 basis, but instead rotate it so we have
// two null vectors to work with (called origin and infinite)
  var ei = 1e4-1e3,           // e-infinite
      eo = 0.5*(1e4+1e3);     // e-origin
  
// Define points, lines, circles using the null basis.  
  var point  = (x,y)=>eo + x*1e1 + y*1e2 + 0.5*(x*x+y*y)*ei,
      line   = (a,b,c)=>!(a*1e1 + b*1e2 + c*ei),
      circle = (x,y,r)=>!(point(x,y) - r**2/2*ei);
  
// Distances and Angles. 
  var dist=(x,y)=>(2*(x<<y).Length)**0.5,
      angle=(x,y)=>Math.acos(!x.Normalized<<!y.Normalized);

// Define three points
  var p1 = point(-0.5, -0.5),
      p2 = point( 1, -0.5), 
      p3 = point(   0,  1.5);
  
// Define two circles, one by wedging 3 points, one directly.
  var C = ()=>p1^p2^p3,        // a function so it updates live.
      D = circle(1,-1,0.9);
  
// Define two lines, one directly, one by wedging two points and infinity.
  var X=line(0,1,0), Y=()=>p2^p3^ei;
      
// Create point pairs by intersecting circle(s) and a line(s).
  var pp1=()=>X&C, pp2=()=>C&D, pp3=()=>Y&D, p4=()=>0.5*(eo<<(X&Y).Normalized)>>>ei;
      
// Graph these items.
  document.body.appendChild(this.graph([
    "2D CGA - drag p1,p2,p3","",                  // title
    0xFF8888, C, "C", D, "D",                     // circles
    0x44AA44, X, "X", Y, "Y", p4,                 // lines
    0x4444FF, pp1, "pp1", pp2, "pp2", pp3, "pp3", // point pairs
    0x666666, p1, "p1", p2, "p2", p3, "p3",       // points
  ],{conformal:true,grid:true}));                 // conformal flag!  

});
</SCRIPT></BODY>